function sumAll(arr) {
    let start = arr[0];
    let end = arr[1];
    if (start > end) {
        let temp = start;
        start = end;
        end = temp;
    }
    return (end - start + 1) * (start + end) / 2;
}

console.log(sumAll([1, 4]));
